package com.qriver.distributedlock.service;

import com.qriver.distributedlock.entity.DistributedLock;
import com.qriver.distributedlock.mapper.DistributedLockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DistributedLockService {

    @Autowired
    private DistributedLockMapper distributedLockMapper;

    public boolean tryLock(String code){
        DistributedLock distributedLock = new DistributedLock();
        distributedLock.setModuleCode(code);
        List<DistributedLock> list = distributedLockMapper.getDistributedLock(distributedLock);
        if(list != null && list.size() > 0){
            return true;
        }
        return false;
    }

}
